package com.zeus.common.utils;

/**
 * Markdown工具
 *
 * @author wangfeixiong126@gmail.com  2021/5/17 00:38
 */
public class MarkdownUtils {

    /**
     * 换行字符串
     */
    public static final String LINE_FEED = "\n";
    /**
     * 双换行字符串
     */
    public static final String DOUBLE_LINE_FEED = "\n\n";

    public static String getTitle(String content, boolean isImport) {
        if (isImport) {
            // 高危
            return "### <font color='#aa2116'>" + content + "</font>" + LINE_FEED;
        }
        return "### " + content + LINE_FEED;
    }

    public static String getItem(String key, Integer value) {
        if (key == null || value == null || key.isEmpty()) {
            return "";
        }
        return ">- " + key + ": " + value + LINE_FEED;
    }

    public static String getItem(String key, String value) {
        if (key == null || value == null || key.isEmpty() || value.isEmpty()) {
            return "";
        }
        // 存在双换行则用代码块包裹
        if (value.contains(DOUBLE_LINE_FEED)) {
            return ">- " + key + ": \n```" + value + "\n```" + LINE_FEED;
        }
        return ">- " + key + ": " + value + LINE_FEED;
    }
}
